package com.powergisol.gis.controller;

import com.powergisol.gis.service.TabStyleService;
import com.powergisol.gis.util.Result;
import com.powergisol.gis.vo.TabStyleVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.List;

/**
 * Date: 2019/7/26  15:45
 * Description:
 */
@RestController
@Api(description = "样式管理" ,value = "样式管理")
public class TabStyleController {
    @Autowired
    private TabStyleService tabStyleService;

    @PostMapping("tabStyleList")
    @ApiOperation(value = "样式管理", notes = "样式管理")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "styleName", value = "样式名称", defaultValue = "1", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "page", value = "页数", defaultValue = "1", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "limit", value = "条数", defaultValue = "10", required = true, paramType = "query")
    })
    public Result tabServiceList(TabStyleVo vo){
        PageHelper.startPage(vo.getPage(), vo.getLimit());
        PageInfo<TabStyleVo> pageInfo = new PageInfo<TabStyleVo>(tabStyleService.tabStyleList(vo));
        Result result = new Result();
        result.setCount((int) pageInfo.getTotal());
        result.setData(pageInfo.getList());
        return result;
    }

    @PostMapping("saveTabStyle")
    @ApiOperation(value = "增加样式", notes = "增加样式")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "styleName", value = "样式文件名称", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "styleContent", value = "样式内容(转义)", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "styleContentOrigin", value = "样式内容(原始)", defaultValue = "0", required = true, paramType = "query"),
    })
    public Result saveTabStyle(TabStyleVo vo){
        Result result = tabStyleService.saveTabStyle(vo);
        return result;
    }

    @PostMapping("getTabStyle")
    @ApiOperation(value = "获取样式", notes = "获取样式")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "id", value = "id", defaultValue = "0", required = true, paramType = "query"),
    })
    public Result getTabStyle(Integer id){
        Result result = tabStyleService.getTabStyle(id);
        return result;
    }

    @PostMapping("upTabStyle")
    @ApiOperation(value = "修改样式", notes = "修改样式")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "id", value = "id", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "styleContentOrigin", value = "样式内容(原始)", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "styleContent", value = "样式内容(转义)", defaultValue = "0", required = true, paramType = "query"),
    })
    public Result upTabStyle(TabStyleVo vo){
        Result result = tabStyleService.upTabStyle(vo);
        return result;
    }

    @PostMapping("isStyleNameDouble")
    @ApiOperation(value = "判断样式名称是否重复", notes = "判断样式名称是否重复")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "styleName", value = "样式文件名称", defaultValue = "0", required = true, paramType = "query")
    })
    public Result isStyleNameDouble(String styleName){
        Result result = new Result();
        result.setData(tabStyleService.isStyleNameDouble(styleName));
        return result;
    }


    @PostMapping("delTabStyle")
    @ApiOperation(value = "删除样式", notes = "删除样式")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "id", value = "样式id", defaultValue = "0", required = true, paramType = "query")
    })
    public Result delTabStyle(Integer id){
        Result result = tabStyleService.delTabStyleById(id);
        return result;
    }

    @PostMapping("selectTabStyle")
    @ApiOperation(value = "样式选择", notes = "样式选择")
    public Result selectTabStyle(){
        TabStyleVo vo = new TabStyleVo();
        List<TabStyleVo> list = tabStyleService.tabStyleList(vo);
        Result result = new Result();
        result.setData(list);
        return result;
    }
}
